package com.xgq.drink.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xgq.drink.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xgq
 * @since 2025-02-23
 */
public interface ProductMapper extends BaseMapper<Product> {
    @Select("SELECT name, description, price, brand,category_id,image_url FROM product WHERE category_id = #{categoryId}")
    IPage<Product> selectPageByCategory(Page<Product> page, Long categoryId);
    @Select("SELECT * FROM product WHERE brand_id = #{brandId}")
    IPage<Product> selectPageByBrandId(Page<Product> page, Long brandId);
    @Update("UPDATE product SET is_del = 1 WHERE product_id = #{productId} AND brand_id = #{brandId}")
    int logicDeleteById(@Param("productId") Long productId, @Param("brandId") Long brandId);
    @Update("UPDATE product SET is_del = 0 WHERE product_id = #{productId} AND brand_id = #{brandId}")
    int openLogicDeleteById(@Param("productId") Long productId, @Param("brandId") Long brandId);
}
